package com.kang.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kang.bean.Role;
import com.kang.mapper.RoleMapper;
import com.kang.mapper.RoleMenusMapper;
import com.kang.mapper.UserMapper;
import com.kang.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @program: service
 * @description:
 * @author: K.faWu
 * @create: 2022-02-28 13:22
 **/
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService  {
    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private RoleMenusMapper roleMenusMapper;


    @Override
    public PageInfo<Role> getList(Role role, Pageable page, HttpServletRequest request) {

        PageHelper.startPage(page.getPageNumber(),page.getPageSize());
        List<Role> list = roleMapper.getList(role);
        return new PageInfo<>(list);
    }

    @Transactional//开启事务
    @Override
    public void delete(List<Role> list) {
        /*
         * 还要删除role_menus表中的数据
         */
        roleMenusMapper.deleteByRoleCodes(list);
        roleMapper.deleteList(list);
    }
}
